#-*- coding: utf-8 -*-
import os, sys, tempfile
has_set = False
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

import logging
logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s', stream=sys.stdout)
#logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s',
#                    filename=BASE_DIR+'/logs/send_feeds.logs',
#                    filemode='a')
logging.getLogger().setLevel(logging.NOTSET)

def set_app_evn():
    global has_set
    if has_set:
        return
    has_set = True
    
    os.chdir(BASE_DIR)
    sys.path.insert(0, BASE_DIR)
    sys.path.insert(0, os.path.join(BASE_DIR, 'libs'))
    sys.path.insert(0, 'C:/Program Files/Google/google_appengine')
    
    #设置app engine环境变量
#    from google.appengine.api import apiproxy_stub_map
#    from google.appengine.api import datastore_file_stub
#
#    app_id = 'myspace-sexy-girls'
#    os.environ['APPLICATION_ID'] = app_id
#    datastore_path = os.path.join(tempfile.gettempdir(),'dev_appserver.datastore')
#    history_path = os.path.join(tempfile.gettempdir(),'dev_appserver.datastore.history')
#    require_indexes = False
#
#    apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
#    datastore = datastore_file_stub.DatastoreFileStub(
#          app_id, datastore_path, history_path, require_indexes=require_indexes)
#    apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore)
    ####################33end
    
    app_id = '3kkk-me'
    os.environ['APPLICATION_ID'] = app_id

    ###############django环境变量
    django_path = os.path.join(BASE_DIR, 'libs/django.zip')
    sys.path.insert(0, django_path)
    from django.core.management import setup_environ
    import settings
    setup_environ(settings)
    ################3end

set_app_evn()   

if __name__ == '__main__':
    import code
    code.interact('App Engine interactive console', None, locals())
